﻿// *----------------------------------------------------------------
// Copyright (C) 2017 通通优品
// 版权所有。
// 
// 类名：CategoryRepository.cs
// 功能描述：TongTongMall.MallWeb.DapperFramework
// 
// Create User：jym 2017/02/09
// 
// Edit User：UserName,EditTime
// Describe：Describe
// ----------------------------------------------------------------*/
using Dapper;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TongTongMall.Dapper;
using TongTongMall.Dapper.DapperExtensions;
using TongTongMall.MallWeb.Core.Components;
using TongTongMall.MallWeb.Core.Components.Models;
using TongTongMall.MallWeb.Core.IRepositories;

namespace TongTongMall.DapperFramework.Repositories.Components
{
    public class CategoryRepository : TongTongMallDbContextBase<DicCategory, int>, ICategoryRepository
    {
        public CategoryRepository(IDbContextProvider<IDatabase> dbContextProvider) : base(dbContextProvider)
        {

        }

        public async Task<List<DicCategoryDto>> GetProductCategoryList(long tenantId)
        {
            var result = await DB.Connection.QueryAsync<DicCategoryDto>(@"SELECT c.cateid, 
                 c.catename, 
                 c.mobileimageid, 
                 c.mobileimageid2, 
                 IMG2.uri AS XURI, 
                 c.[path], 
                 c.pcateid, 
                 img.uri 
          FROM   diccategory c 
                 LEFT JOIN ImageInfo img 
                        ON c.imageid = img.imageid 
                 LEFT JOIN ImageInfo IMG2 
                        ON c.mobileimageid2 = IMG2.imageid 
          WHERE  c.catetype = 10 
                 AND c.showstatus = 1 
                 AND c.delstatus IS NULL 
                 AND c.tenantid = @TenantId 
          ORDER  BY c.sort ASC, 
                    c.updatedate DESC ", new { TenantId = tenantId }, commandType: CommandType.Text);
            return result.ToList();
        }


    }
}
